package info.nightbrest.agt.shared.rpc.action;

import com.google.gwt.core.client.JavaScriptObject;
import info.nightbrest.agt.client.Constants;
import info.nightbrest.agt.shared.rpc.SimpleResult;

public class LoginAction extends AbstractAction<LoginAction.Result>
{
	public LoginAction(String loginName, String password)
	{
		init();
		Request request = (Request) getRequestData();

		request.setLoginName(loginName);
		request.setPassword(password);
	}

	@Override
	public void init()
	{
		setRequestData((Request) JavaScriptObject.createObject());
		setRequestUri(Constants.getActionUri("/Account/Login"));
		setResult(new Result());
	}

	public final static class Request extends JavaScriptObject
	{
		public native final String getLoginName() /*-{ return this.loginName; }-*/;
		public native final String getPassword()  /*-{ return this.userPassword; }-*/;

		public native final void setLoginName(String loginName) /*-{ this.loginName = loginName; }-*/;
		public native final void setPassword(String password)   /*-{ this.password = password; }-*/;

		protected Request() {}
	}

	public final class Result extends SimpleResult
	{
	}

	public final static class Response extends JavaScriptObject
	{
		public native final String getUserName()     /*-{ return this.user.name; }-*/;
		public native final String getUserFullName() /*-{ return this.user.fullname; }-*/;
		public native final String getUserEmail()    /*-{ return this.user.email; }-*/;

		protected Response()
		{
		}
	}
}
